$(document).ready(function(){
	 //external
    $('a[rel="external"]').attr('target', '_blank');
    //placeholder
    if(!Modernizr.input.placeholder){
	$('[placeholder]').focus(function() {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
		input.val('');
		input.removeClass('placeholder');
	}
	}).blur(function() {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder')) {
		input.addClass('placeholder');
		input.val(input.attr('placeholder'));
	}
	}).blur();
		$('[placeholder]').parents('form').submit(function() {
		$(this).find('[placeholder]').each(function() {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
			input.val('');
		}
		})
	});
}
	//select
	$('.wd-langue,.wd-web,.wd-select-Internal,.wd-nav-select').msDropdown({roundedBorder:false});
	// menu device
    var pull = $('a.wd-pull');
    	menuDevice = $('.wd-nav-device ul.wd-drop-parent');
    	pull.on('click',function(e){
    	e.preventDefault();
    	menuDevice.slideToggle();
    });
    $('a.wd-pull').bind('click',function(e){
		e.stopPropagation();
		$(document).bind('click',function(){$('.wd-nav-device ul.wd-drop-parent').slideUp(500);});
	});
	$('ul.wd-drop-parent > li > ul').hide().click(function(e){
		e.stopPropagation();
	});
	$('ul.wd-drop-parent > li').toggle(
		function(){
			$(this).addClass('current');
			//$(this).find('.wd-drop-children').slideDown("slow");
			
		}
		,function(){
			$(this).removeClass('current');
			//$(this).find('.wd-drop-children').slideUp("slow");
	});
	//banner
	$('#camera_wrap_2').camera({
		height: '37%',
		pagination: false,
		thumbnails: true,
		loader: false,
        caption: true,
        navigation: false,
        fx: 'mosaic'
	});
    //table
    $('.wd-table table').find('tr:even').addClass('wd-even');
    //
    $(".setQuestions").click(function (e)
	{
		ShowDialog(true);
		e.preventDefault(false);
	});
	$(".wd-btnClose").click(function (e)
	{
		HideDialog();
		e.preventDefault();
	});
	//switcher
	var cookieName = 'theme';
	var cookieOptions = {path: '/', expires: 3};
	if ($.cookie(cookieName) == null){
		$.cookie(cookieName, 1, cookieOptions);
	}
	$('body').addClass('theme' + $.cookie(cookieName));
	$('ul.wd-themes > li').eq($.cookie(cookieName) - 1).addClass('wd-current');
	var totalTheme = $('ul.wd-themes > li').length;
	$('ul.wd-themes').find('a').each(function(e){
		$(this).click(function(){
			$.cookie(cookieName, $(this).attr('rel'), cookieOptions);
			$('ul.wd-themes > li').removeClass('wd-current').eq($.cookie(cookieName) - 1).addClass('wd-current');
			for (var i=1; i<=totalTheme ; i++ ){
				$('body').removeClass('theme' + i);
			}
			$('body').addClass('theme' + $.cookie(cookieName));
			return false;
		});
	});
	//carouFredSel
	$('#wd-foo').carouFredSel({
		auto: false,
		responsive: true,
		width: '100%',    
		scroll: 1,
		prev: '#wd-prev',
		next: '#wd-next',
		pagination: false,
		mousewheel: true,
		items: {
		height: 'auto',
		width: '126',
		visible: {
		min: 1,
		max: 5
		}
		},
		swipe: {
		onMouse: true,
		onTouch: true
		}
	});
    $('#linkWebsite').live('change',function(){
        var _link = $(this).val();
         window.open(_link);
    });    
});
//popup
//function gate-information
function ShowDialog(modal)
{
	$("#wd-overlay").show();
	$("#wd-message").fadeIn(300);

	if (modal)
	{
		$("#wd-overlay").unbind("click");
	}
	else
	{
		$("#wd-overlay").click(function (e)
		{
			HideDialog();
		});
	}
}
function HideDialog()
{
	$("#wd-overlay").hide();
	$("#wd-message").fadeOut(300);
}